#include "CommandManage.h"

//#pragma disable(warning: 4267)


////////////////////////////////////////////////////////////////////////// 
// Transform operation for view

bool g_bTransformSwitch = true;
void SetTransformState(bool bTransformSwitch)
{ g_bTransformSwitch = bTransformSwitch; }
bool GetTransformState()
{ return g_bTransformSwitch; }


//////////////////////////////////////////////////////////////////////////
// Implementation of command factory

void CCmdFactory::AddToLiveList(CCmdBase *pCmd)
{
	if(FindCmdInLiveList(pCmd) == _liveCmdList.end()){
		_liveCmdList.push_back(pCmd);
	}
}

void CCmdFactory::DelLiveCmd(CCmdBase *pCmd)
{
	CmdList::iterator find = FindCmdInLiveList(pCmd);
	if(find != _liveCmdList.end()){
		_liveCmdList.erase(find);
	}
}

void CCmdFactory::StopAllLiveCmd()
{
	CmdList::iterator it = _liveCmdList.begin(), nextIt;
	//size_t nListSize = _liveCmdList.size();
	for(; it != _liveCmdList.end(); ){
		nextIt = it;
		nextIt ++;
		(*it)->EndCmd();
		it = nextIt;
	}
}

CCmdFactory::CmdList::iterator CCmdFactory::FindCmdInLiveList(CCmdBase *pCmd)
{
	CmdList::iterator it = _liveCmdList.begin();
	for(; it != _liveCmdList.end(); it ++){
		if(*it == pCmd){
			return it;
		}
	}

	return it;
}

void CCmdFactory::PassMsgToLiveCmd(CMsg& msg)
{
	// Note: the active command may be deleted from list during handling
	CmdList::iterator it = _liveCmdList.begin(), nextIt;
	for(; it != _liveCmdList.end();){
		nextIt = it;
		nextIt ++;
		(*it)->HandleMsg(msg);
		it = nextIt;
	}

	return;
}

//////////////////////////////////////////////////////////////////////////
// Declaration of all commands instance
CCmdFactory::CmdList CCmdFactory::_liveCmdList; // live commands list
CTestCmd CCmdFactory::_testCmd;  // Test command

/*
CTriPointCloudCmd CCmdFactory::_pointCloudTriCmd; // Point cloud triangulation command
CIntersectPointCloudMeshCmd CCmdFactory::_pointCloudMeshInterCmd; // Intersecting point cloud meshes command
*/